package red_book.year2024.month9;

import java.util.Scanner;

public class Robot {
    public static int [][]trues;
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        String[] map=new String[n];
        scanner.nextLine();
        for (int i = 0; i < n; i++) {
            map[i] = scanner.nextLine();
        }
        trues=new int[n][m];
        int count=0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if(dfs(map,new int[n][m],i,j)){
                    count++;
                    trues[i][j]=1;
                }else{
                    trues[i][j]=-1;
                }
            }
        }
        System.out.println(n*m-count);
    }
    public static boolean dfs(String []map,int [][]vis,int i,int j){
        if(i<0||i>=map.length||j<0||j>=map[0].length()||trues[i][j]==1){
            return true; //出去了
        }
        if(trues[i][j]==-1){
            return false;
        }
        if(vis[i][j]==1){
            return false;
        }
        vis[i][j]=1;
        char c=map[i].charAt(j);
        if(c=='U'){
            return dfs(map,vis,i-1,j);
        }
        if(c=='D'){
            return dfs(map,vis,i+1,j);
        }
        if(c=='L'){
            return dfs(map,vis,i,j-1);
        }
        if(c=='R'){
            return dfs(map,vis,i,j+1);
        }
        return false;
    }
}
